package com.longge;

import java.util.ArrayList;
import java.util.List;

public class IncreasingBST {
    List<Integer> nums = new ArrayList<>();

    public TreeNode increasingBST(TreeNode root) {

        dfs(root);
        return buildTree(nums, 0);

    }

    private TreeNode buildTree(List<Integer> nums, int i) {
        if (i == nums.size()) return null;
        TreeNode root = new TreeNode(nums.get(i));
        root.right = buildTree(nums, i + 1);

        return root;
    }

    private void dfs(TreeNode root) {
        if (root == null) return;
        dfs(root.left);
        nums.add(root.val);
        dfs(root.right);
    }
}
